/*
 * @Author: 陈永浩(cyh1231wp@163.com)
 * @Date: 2020-11-06 16:58:24
 * @LastEditors: 陈永浩(cyh1231wp@163.com)
 * @LastEditTime: 2021-02-09 12:19:21
 */
export function convertRouter(menu) {
  if (menu && menu.length > 0) {
    return menu && menu.map((m) => {
      const route = {};
      if (m.url) {
        if (m.url[0] != '/') {
          m.url = '/' + m.url;
        }
        if (m.url.indexOf('layouts/') >= 0) {
          route.component = (resolve) => require([`@/views${m.url}`], resolve)
        } else {
          route.component = (resolve) => require([`@/views/pages${m.url}`], resolve)
        }
        route.path = m.path || m.url;
        route.name = m.name || m.url;

      }
      if (m.children && m.children.length)
        route.children = convertRouter(m.children)
      if (m.children && m.children.length === 0) delete route.children
      return route
    })
  } else {
    return null
  }

}